package com.rfsp.common.interceptor;

import java.lang.reflect.Method;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.MethodParameter;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.rfsp.common.base.BaseController;
@Component
public class LoggerInterceptor implements HandlerInterceptor {
	
	public Logger log = LoggerFactory.getLogger(LoggerInterceptor.class);

	//		交给日志切片去做LogAspect
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		/*
		if (handler instanceof HandlerMethod) {
			try {
				HandlerMethod handlerMethod = (HandlerMethod) handler;
				// 获取处理器方法的声明类
				Class<?> declaringClass = handlerMethod.getBeanType();
				// 获取处理器方法对象
				Method method = handlerMethod.getMethod();
				// 获取处理器方法参数
				MethodParameter[] parameters = handlerMethod.getMethodParameters();
				// 获取处理器方法返回值类型
				MethodParameter returnType = handlerMethod.getReturnType();

				log.info("logger-begin: {}", handler);
				for (int i = 0; i < parameters.length; i++) {
					log.debug("请求参数-{}: {}[{}]", i, parameters[i].getParameterName(), parameters[i]);
				}
			} catch (Exception ignored) {
				log.error("Exception:", ignored);
			}
			
			
		} */
		return true;
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
//			log.info("logger-endle: {}", handler);
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
	}
}
